#pragma once

#include "Statement.h"
#include "Statement_List.h"
#include "Expression.h"

MAKE_PTR(CStatementIf);

class CStatementIf : public CStatement
{
public:
	static CStatementIfPtr create(CExpressionPtr exp,
		CStatementListPtr statement_true,
		CStatementListPtr statement_false = CStatementListPtr())
	{
		return CStatementIfPtr(new CStatementIf(exp, statement_true, statement_false));
	}

public:
	CStatementIf(CExpressionPtr exp, 
		CStatementListPtr statement_true, 
		CStatementListPtr statement_false = CStatementListPtr())
		:m_pExp(exp), m_pStatement_true(statement_true), m_pStatement_false(statement_false)
	{

	}

protected:
	CExpressionPtr m_pExp;
	CStatementListPtr m_pStatement_true;
	CStatementListPtr m_pStatement_false;

protected:
	EvalType doEval()
	{
		if (m_pExp->eval())
		{
			m_pStatement_true->eval();
		}
		else
		{
			if (m_pStatement_false)
			{
				m_pStatement_false->eval();
			}
			
		}
		return 0;
	}
};